package string.leetcode;

/**
 * @author yuisama
 * @date 2022/11/03 18:12
 * 字符串中的单词数
 **/
public class Num434_CountSegments {
    public int countSegments(String s) {
        if(s == null || s.length() == 0) {
            return 0;
        }
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if ((i == 0 || s.charAt(i - 1) == ' ' ) && s.charAt(i) != ' ') {
                count ++;
            }
        }
        return count;
    }
}